<template>
  <div class="comment">
    <div class="userinfo">
      <div class="userimg">
        <slot name="userimg"></slot>
      </div>
      <div class="rightinfo">
        <div class="top">
          <span class="userName" ref="userName">
            <slot name="userName"></slot>
          </span>
        </div>
        <!-- 回复内容 -->
        <div class="replyContent">
          <p ref="commentCont">
            <slot name="replyContent"></slot>
          </p>
        </div>
        <div class="fbTime">
          <p>
            <slot name="fbTime"></slot>
          </p>
          <div class="btn" @click="reply"><i class="iconfont icon-pinglun"></i><span>评论</span></div>
        </div>
        <!-- 其他人的回复 -->
        <div class="otherComments animate__animated animate__fadeIn" v-if="islookComOrPackup == 1">
          <slot name="otherComments"></slot>
        </div>
      </div>
    </div>

    <div v-if="relyNumber > 0">
      <!-- 定义其他人回复的功能 -->
      <div class="allComment" v-if="islookComOrPackup == 0">
        <!-- <span>共有</span>
        <span class="commentNumber">
          <slot name="commentNumber"></slot>
        </span>
        <span>条回复，</span> -->
        <span class="lookcomment" @click="lookcomment">
          <span>查看全部</span>
          <span class="commentNumber">
            <slot name="commentNumber"></slot>
          </span>
          <span>条回复</span>
        </span>
      </div>

      <!-- 收起评论 -->
      <div class="packup" @click="islookComOrPackup = 0" v-if="islookComOrPackup == 1">收起评论</div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const $emit = defineEmits(['reply', 'lookcomment'])
const props = defineProps({
  ceid: {
    type: String
  },
  //当前楼层回复的数量
  relyNumber: {
    type: Number
  }
})
// 当前显示的是查看评论还是展开评论,0点击查看 1收起评论
const islookComOrPackup = ref(0)
const userName = ref<any>(null)
const commentCont = ref<any>(null)
const reply = () => {
  //需要回复用户的昵称
  let replyUser = {
    name: userName.value.innerHTML,
    oldreplyCon: commentCont.value.innerHTML,
    ceId: props.ceid
  }
  $emit('reply', replyUser)
}
const lookcomment = () => {
  islookComOrPackup.value = 1
  $emit('lookcomment', props.ceid)
}
</script>
<style lang="scss" scoped>
.comment {
  padding: 15px 8px;
  border-bottom: 1px solid #e4e7ed;
  // box-shadow: 0px 0px 8px rgba(0,0,0,.1);
  margin-bottom: 20px;
  color: #606266;
  font-size: 16px;

  // 展开所有评论
  .allComment {
    margin-top: 15px;
    padding-left: 51px;

    .commentNumber {
      // font-weight: 600;
    }

    .lookcomment {
      font-size: 14px;
      color: rgb(138, 145, 159);
      cursor: pointer;

      &:hover {
        color: #1e80ff;
      }
    }
  }

  // 收起评论
  .packup {
    padding-left: 51px;
    color: rgb(138, 145, 159);
    font-size: 14px;
    cursor: pointer;

    &:hover {
      color: #1e80ff;
    }
  }

  //用户昵称
  .userName {
    color: rgb(81, 87, 103);
    // color: #606266;
    // font-weight: 600;
  }

  //发布时间
  .fbTime {
    display: flex;
    align-items: center;

    p {
      margin: 0;
      font-size: 14px;
      color: rgb(138, 145, 159);
    }

    .btn {
      cursor: pointer;
      height: 14px;
      width: 45px;
      text-align: center;
      line-height: 14px;
      display: flex;
      align-items: center;
      font-size: 14px;
      white-space: nowrap;
      margin-left: 10px;
      color: rgb(37, 41, 51);
      margin-right: 20px;
      border-radius: 2px;

      span {
        margin-left: 5px;
      }

      &:hover {
        color: #1e80ff;
      }
    }
  }

  // 用户信息
  .userinfo {
    display: flex;
    // margin-bottom: 10px;
    // height: 50px;
    align-items: center;

    .userimg {
      display: flex;
      margin-bottom: auto;
      margin-right: 15px;
      border-radius: 50%;
      overflow: hidden;
      flex-shrink: 0;

      ::v-deep(img) {
        width: 36px;
        height: 36px;
      }
    }

    .rightinfo {
      flex: 1;

      .top {
        display: flex;
        justify-content: space-between;
        margin-bottom: 4px;

        .userName {
          color: rgb(81, 87, 103);
        }
      }
    }
  }

  .otherComments {
    padding-right: 16px;
    padding-bottom: 16px;
    // margin-left: 40px;
    // background-color: #f3f3f3;
  }
}

.replyContent {
  margin-bottom: 8px;
  font-size: 16px;
  color: rgb(37, 41, 51);

  p {
    margin: 0;
  }
}
</style>
